#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1 
#define ERROR 0
#define UNDERFLOW -1
#define OVERFLOW -2
#define MAXSIZE 12500
typedef int Status;
typedef int ElemType;
typedef struct OLNode
{
    int i, j;
    ElemType e;
    struct OLNode *right, *down;
}OLNode, * OLink;
typedef struct
{
    OLink *rhead, *chead;
    int mu, nu, tu;
}CrossList;
Status CreateSMatrix_OL(CrossList &M)
{
    // if (M)
    //     free(M);
    int m, n, t;
    scanf("%d%d%d", &m, &n, &t);
    M.mu = m;
    M.nu = n;
    M.tu = t;
    if (!(M.rhead = (OLink *)malloc((m + 1) * sizeof(OLink))))
        exit(OVERFLOW);
    if (!(M.chead = (OLink *)malloc((m + 1) * sizeof(OLink))))
        exit(OVERFLOW);
    for (int i = 1; i <= m; ++i)
        M.rhead[i] = NULL;
    for (int i = 1; i <= n; ++i)
        M.chead[i] = NULL;
    int i, j, e;
    for (scanf("%d%d%d", &i, &j, &e); i != 0; scanf("%d%d%d", &i, &j, &e))
    {
        OLink p;
        if (!(p = (OLNode *)malloc(sizeof(OLNode))))
            exit(OVERFLOW);
        p->i = i;
        p->j = j;
        p->e = e;
        if (M.rhead[i] == NULL && M.rhead[i]->j > j)
        {
            p->right = M.rhead[i];
            M.rhead[i] = p;
        }
        else
        {
            OLink q;
            for (q = M.rhead[i]; q->right && q->right->j < j; q = q->right);
            p->right = q->right;
            q->right = p;

        }
        if (M.chead[j] == NULL && M.chead[j]->down->i > i)
        {
            p->right = M.chead[j];
            M.chead[j] = p;
        }
        else
        {
            OLink q;
            for (q = M.chead[j]; q->down && q->down->i < i; q = q->down);
            p->down = q->down;
            q->down = p;
        }
    }
    return OK;
}

int main(void)
{
    int * p = NULL;
    if (p)
        printf("haha");
    return 0;
}